﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using IOSpro.Lib;
using IosDatamodel;
using IOSpro.Models;
namespace IOSpro.Controllers
{
    public class QRcodeController : Controller
    {
        //
        // GET: /QRcode/
        private IosDBEntities db;
        private IQRBL ibl;
        public QRcodeController()
        { 
            db=new IosDBEntities();
            ibl = new QRBL(this.ModelState);

        }

        public ActionResult ProductQRIndex()
        {
            var aa = ibl.GetProductQRList();

            return View(aa);
        }

        public ActionResult VideoQRIndex()
        {
            var aa = ibl.GetVIdeoQRList();

            return View(aa);
        }


        //
        // GET: /QRcode/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /QRcode/Create

        [HttpPost]
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                // TODO: Add insert logic here
                ibl.AddProductQRString(collection["QRString"]);

                return View();
            }
            catch
            {
                return View();
            }
        }


        public ActionResult CreateVideoQR()
        {
            return View();
        }

        //
        // POST: /QRcode/Create

        [HttpPost]
        public ActionResult CreateVideoQR(FormCollection collection)
        {
            try
            {
                // TODO: Add insert logic here
                ibl.AddVideoQRString(collection["videoqr"]);

                return View();
            }
            catch
            {
                return View();
            }
        }

        [HttpGet]
        public ActionResult VideoCode(string codestring) {


            var aa = (from z in db.Videos where z.VideoCode == codestring select z).FirstOrDefault();
            if (aa==null) return null;
                else
            return View(aa);
        
        }



        //
        // GET: /QRcode/Edit/5
 
        public ActionResult Edit(int id)
        {
            return View();
        }

        //
        // POST: /QRcode/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /QRcode/Delete/5
 
        public ActionResult Delete(int id)
        {
            return View();
        }

        //
        // POST: /QRcode/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
